package com.houdoudou.servlet.jsp;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.houdoudou.affair.jsp.Common;
import com.houdoudou.affair.jsp.DatabaseAffairJsp;
import com.houdoudou.affair.jsp.SuperProgrammerAffairJsp;

public class SuperProgrammerServletJsp extends HttpServlet{

	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		process(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		process(req, resp);
	}
	
	void process(HttpServletRequest req, HttpServletResponse resp){
		
		String affair="";
		    try {
				req.setCharacterEncoding("UTF-8");
				  resp.setCharacterEncoding("UTF-8");
					 affair=req.getParameter("affair");
					 System.out.println("affair="+affair + "  时间----"+ new Date());
					 
					 
		 //创建 数据库
		 if(affair.equals("createDatabase")){ 
			 DatabaseAffairJsp.createDatabase(req,resp);	 
		 }
		 //创建 数据表 
		 if(affair.equals("createTable")){ 
			 DatabaseAffairJsp.createTable(req, resp);					 
		 }
		//程序员登陆		
		 if(affair.equals("programmerLogin")){ 
			 SuperProgrammerAffairJsp.programmerLogin(req, resp);				
		 }
		//程序员登陆		
		 if(affair.equals("programmerLogout")){ 
			 req.getSession().invalidate();
			 req.getSession().removeAttribute("loginedTelnum");
			Common.redirectToJsp(req, resp, req.getContextPath()+"/programmer/programmerLogin.jsp");
			
			 
		 }
		 
		 //新增程序员
		 if(affair.equals("createProgrammer")){ 		
			 SuperProgrammerAffairJsp.createProgrammer(req, resp);			
		 }
		 //搜索程序员 	
		 if(affair.equals("searchProgrammer")){ 
			 SuperProgrammerAffairJsp.searchProgrammer(req, resp);			
		 }
		 //删除程序员 		
		 if(affair.equals("deleteProgrammer")){ 
			 SuperProgrammerAffairJsp.deleteProgrammer(req, resp);			
		 }	 		
		 //修改程序员		
		 if(affair.equals("modifyProgrammer")){ 
			 SuperProgrammerAffairJsp.modifyProgrammer(req, resp);			
		 }
		//更新程序员		
		 if(affair.equals("updateProgrammer")){ 
			 SuperProgrammerAffairJsp.updateProgrammer(req, resp);			
		 }
		 //新增财务人员
		 if(affair.equals("createFinancer")){ 		
			 SuperProgrammerAffairJsp.createFinancer(req, resp);			
		 }
		//搜索财务人员
		 if(affair.equals("searchFinancer")){ 		
			 SuperProgrammerAffairJsp.searchFinancer(req, resp);			
		 }
		//删除财务人员
		 if(affair.equals("deleteFinancer")){ 		
			 SuperProgrammerAffairJsp.deleteFinancer(req, resp);			
		 }
		 
		    } catch (UnsupportedEncodingException e) {
			    // TODO Auto-generated catch block
			    e.printStackTrace();
	         	 }  	 
	}
	

}
